package cn.com.darly.videoandroidpm.ui.presenter;

import com.darly.common.ToastApp;
import com.darly.common.retrofit.FrameListener;

import java.util.Map;

import cn.com.darly.videoandroidpm.base.BaseActivity;
import cn.com.darly.videoandroidpm.bean.BaseBean;
import cn.com.darly.videoandroidpm.ui.biz.BeenFriendListener;
import cn.com.darly.videoandroidpm.widget.shapeloading.ShapeLoadingDialog;


/**
 * @author zhangyh2 s 上午10:57:39 TODO 控制器 页面动作操作
 */
public class BeenFriendPresenter {

    private BeenFriendListener userBiz;
    private BeenFriendListener.BeenFriendInterface main;

    private ShapeLoadingDialog loading;


    public BeenFriendPresenter(BeenFriendListener.BeenFriendInterface main) {
        this.main = main;
        this.userBiz = new BeenFriendListener();
        loading = new ShapeLoadingDialog.Builder((BaseActivity)main)
                .loadText("请求中...")
                .build();
    }



    public void aie(Map<String, String> params) {
        userBiz.onStart(loading);
        main.setDisableClick();
        userBiz.onAre(params, new FrameListener<BaseBean<Object>>() {
            @Override
            public void onSucces(BaseBean<Object> info) {
                main.setEnableClick();
                userBiz.onStop(loading);
                main.onBeenFriendSuccess(info.getData());
            }

            @Override
            public void onFaild(int code, String info) {
                main.setEnableClick();
                userBiz.onStop(loading);
                if (code == 0){
                    ToastApp.showToast("服务端更新，请更新应用版本！");
                }else {
                    main.onBeenFriendFailed(info);
                }
            }
        });
    }
}